<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="net.sureon.common.I18nSupport"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ page import="net.sureon.dao.*"%>
<%@ page import="java.text.*"%>
<%
	List<DailyTiming> all = null;
	all = (List<DailyTiming>) request.getAttribute("all");
%>
<%
int currentPage = (Integer)request.getAttribute("currentPage");
int pageCounter = (Integer)request.getAttribute("pageCounter");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>我的考勤</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<script type="text/javascript">
function validateForm(){
// 判断日期
	 var   strSeparator   =   "-";   //日期分隔符  
        var   strDateArray;  
        var   intYear;  
        var   intMonth;  
        var   intDay;  
        var   boolLeapYear;  
        var strDate=document.getElementById("currentDate").value;   //表单中的日期值
        strDateArray   =   strDate.split(strSeparator);  
         
        if(strDateArray.length!=3)    {   alert('日期格式错误'); return   false;   }
         
        intYear   =   parseInt(strDateArray[0],10);  
        intMonth   =   parseInt(strDateArray[1],10);  
        intDay   =   parseInt(strDateArray[2],10);  
         
        if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay))   {   alert('日期格式错误'); return   false;   }
         
        if(intMonth>12||intMonth<1)    {   alert('日期格式错误'); return   false;   } 
         
        if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1))   {   alert('日期格式错误'); return   false;   } 
         
        if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1))   {   alert('日期格式错误'); return   false;   }
         
        if(intMonth==2){  
              if(intDay<1)   {   alert('日期格式错误'); return   false;   }
               
              boolLeapYear   =   false;  
              if((intYear%100)==0){  
                    if((intYear%400)==0)   boolLeapYear   =   true;  
              }  
              else{  
                    if((intYear%4)==0)   boolLeapYear   =   true;  
              }  
               
              if(boolLeapYear){  
                    if(intDay>29) {   alert('日期格式错误'); return   false;   }
              }  
              else{  
                    if(intDay>28)  {   alert('日期格式错误'); return   false;   }
              }  
        }  
         
        return   true;  	
}
function changeStatus(xxx) {
	document.aspnetForm.status.value =xxx;
	return true; 
}

function deleteDailyTimingControl() {
	if(confirm("是否删除?")) {
		return true;
	}
		else {
		return false;	
	}
}
</script>
</HEAD>
<BODY>
<jsp:include page="../header.jsp"></jsp:include>
<DIV>
<TABLE class=style1 cellSpacing=0 cellPadding=0>
	<TR>
		<TABLE class="style5" cellSpacing=0 cellPadding=0>
			<TBODY>
				<TR>
					<TD class=style6 style="TEXT-ALIGN: left" bgColor=#fffbd6 colSpan=5>
					<TABLE class=ctl00_ContentPlaceHolder1_Menu1_2
						id=ctl00_ContentPlaceHolder1_Menu1 cellSpacing=0 cellPadding=0
						border=0>
						<TBODY>
							<TR>
								<TD id=ctl00_ContentPlaceHolder1_Menu1n0 onkeyup=Menu_Key(this)
									onmouseover=Menu_HoverStatic(this)
									onmouseout=Menu_Unhover(this)>
								<TABLE
									class="ctl00_ContentPlaceHolder1_Menu1_4 ctl00_ContentPlaceHolder1_Menu1_9"
									cellSpacing=0 cellPadding=0 width="100%" border=0>
									<TBODY>
										<TR>
											<TD style="WHITE-SPACE: nowrap"><A
												class="ctl00_ContentPlaceHolder1_Menu1_1 ctl00_ContentPlaceHolder1_Menu1_3 ctl00_ContentPlaceHolder1_Menu1_8"
												href="<%=request.getContextPath() %>/user/myDailyTiming.do">可编辑的考勤</A></TD>
										</TR>
									</TBODY>
								</TABLE>
								</TD>
								<TD style="WIDTH: 3px"></TD>
								<TD id=ctl00_ContentPlaceHolder1_Menu1n1 onkeyup=Menu_Key(this)
									onmouseover=Menu_HoverStatic(this)
									onmouseout=Menu_Unhover(this)>
								<TABLE class=ctl00_ContentPlaceHolder1_Menu1_4 cellSpacing=0
									cellPadding=0 width="100%" border=0>
									<TBODY>
										<TR>
											<TD style="WHITE-SPACE: nowrap"><A
												class="ctl00_ContentPlaceHolder1_Menu1_1 ctl00_ContentPlaceHolder1_Menu1_3"
												href="myConfirmApply.do">已批准的考勤</A></TD>
											<td valign="top"> 
											<br></td>
										</TR>
									</TBODY>
								</TABLE>
								</TD>
							</TR>
						</TBODY>
					</TABLE>
					</TD>
				</TR>
		
				<TR>
					<TD style="TEXT-ALIGN: left" colSpan=5>
					<TABLE class=style5 cellSpacing=0 cellPadding=0 width="1108"
						height="20">
						<TBODY>
							<TR>
								<TD style="TEXT-ALIGN: left">
								<DIV>
								<TABLE id=ctl00_ContentPlaceHolder1_GridView2
									style="FONT-SIZE: small; WIDTH: 100%; COLOR: #333333; FONT-FAMILY: Arial; BORDER-COLLAPSE: collapse"
									cellSpacing=0 cellPadding=4 border=0>
									<TBODY>
										<TR
											style="FONT-WEIGHT: bold; COLOR: white; BACKGROUND-COLOR: #507cd1"
											align=middle>
											<TH scope=col style="COLOR: white">日期</TH>
											<TH scope=col style="COLOR: white">星期</TH>
											<TH scope=col style="COLOR: white">工作时间</TH>
											<TH scope=col style="COLOR: white">加班时间</TH>
											<TH scope=col style="COLOR: white">休假时间</TH>
											<TH scope=col style="COLOR: white">请假时间</TH>
											<TH scope=col style="COLOR: white">工作内容/描述</TH>
											<TH scope=col style="COLOR: white">提交时间</TH>
											<TH scope=col style="COLOR: white">状态</TH>
											<th scope=col style="COLOR: white">&nbsp;&nbsp;</th>
										</TR>
										<%
											if (all == null || all.size() == 0) {
										%>
										<%
											} else {
												String bgColor=null;
												String color_a = "#FFFFFF";
												String color_b = "#EFF3FB";
												for (int i = 0; i < all.size(); i++) {
													DailyTiming dt = all.get(i);
													Date date = dt.getWorkDate();
													bgColor = (i%2 == 0)?color_a:color_b;
													java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
															"E");
													java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat(
															"yyyy-MM-dd HH:mm:ss");		
													DecimalFormat df = new DecimalFormat("####");
										%>
										<TR style="BACKGROUND-COLOR: <%=bgColor%>" align="middle">
											<TD style="WIDTH: 75px"><a href="<%=request.getContextPath() %>/user/myDailyTiming.do?showContent=yes&dailyTimingID=<%=dt.getDailyTimingID() %>"><%=dt.getWorkDate()%></a></TD>
											<TD style="WIDTH: 75px"><%=sdf.format(date) %></TD>
											<TD style="WIDTH: 60px"><%=df.format(dt.getWorkTime())%></TD>
											<TD style="WIDTH: 60px"><%=df.format(dt.getOverTime())%></TD>
											<TD style="WIDTH: 60px"><%=df.format(dt.getVocationTime())%></TD>
											<TD style="WIDTH: 60px"><%=df.format(dt.getLeaveTime())%></TD>
											<TD >
										 <%
												String summary = dt.getWorkSummary();
											if(summary.length() > 73){
												summary = summary.substring(0, 70);
												summary = summary + "...";
											}
											out.print(summary);
											%>
											</TD>
											<TD style="WIDTH: 85px"><%=sdf2.format(dt.getSubmitDate()) %></TD>
											<TD style="WIDTH: 40px"><%=I18nSupport.getMessage(dt.getStatus()) %></TD>
										
											<TD style="WIDTH: 30px">
												<%
													if("Saved".equals(dt.getStatus()) || "Rejected".equals(dt.getStatus()))
													{
												 %>		
												<a href="<%=request.getContextPath() + "/user/deleteDailyTiming.do?dailyTimingID=" + dt.getDailyTimingID() %>" onclick="return deleteDailyTimingControl()">删除</a>
												<%
													}else {
												%>
													删除
												<%
													}	
												 %>
											</TD>
										
										</TR>
										<%
												}
											}
										%>
										
									</TBODY>
								</TABLE>
								</DIV>
								</TD>
								</TR>
								<TR>
									<TD style="TEXT-ALIGN: center">
										<jsp:include page="../splitPage.jsp">
										<jsp:param name="url" value="/user/myDailyTiming.do"/>
										<jsp:param name="currentPage" value="<%=currentPage %>"/>
										<jsp:param name="pageCounter" value="<%=pageCounter %>"/>
										</jsp:include>
									</TD>
								</TR>
						</TBODY>
					</TABLE>
					</TD>
	

<TR>
					<TD style="TEXT-ALIGN: left; color: red" colSpan=5>
					<%
								String errorMsg = (String)request.getAttribute("errorMsg");
								if(errorMsg != null && errorMsg.equals("already_submitted")) {
									out.println("对不起， 该考勤记录已存在!");
									//<!--<script type='text/javascript'>alert('Sorry, that dailyTiming is exists!');</script> -->
								}
							 %>	
</TD>
</TR>
		<FORM id=aspnetForm name=aspnetForm action="<%=request.getContextPath()%>/user/apply.do" method=post  onsubmit="return validateForm();">
				<TR>
					<TD style="TEXT-ALIGN: center" colSpan=5>
					<DIV id=ctl00_ContentPlaceHolder1_Panel1>
					<TABLE class=style5 cellSpacing=0 cellPadding=0>
						<TBODY>
						
						<%
								DailyTiming dt = (DailyTiming)request.getAttribute("dailyTiming");
									if(dt == null) {
							
						 %>
						
						
							<TR>
								<TD style="TEXT-ALIGN: left"><SPAN
									id="xxxxxx" style="FONT-SIZE: small">考勤日期：</SPAN>
								<INPUT id="currentDate"
									style="FONT-SIZE: small; WIDTH: 86px; COLOR: #0000cc; HEIGHT: 16px"
									value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
									name="workDate"></TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label14 style="FONT-SIZE: small">工作时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox8
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=8 name="workTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label15 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label16 style="FONT-SIZE: small">加班时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox9
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=0 name="overTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label17 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label18 style="FONT-SIZE: small">休假时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox10
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=0 name="vocationTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label19 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label20 style="FONT-SIZE: small">请假时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox11
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=0 name="leaveTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label21 style="FONT-SIZE: small">小时</SPAN>
								</TD>
							</TR>
							<TR>
								<TD colSpan=5><TEXTAREA
									id=ctl00_ContentPlaceHolder1_TextBox12
									style="WIDTH: 99.5%; COLOR: #0000cc; HEIGHT: 80px"
									name="workSummary">工作内容/备注：</TEXTAREA></TD>
							</TR>
						<%
								} else {
								
						%>
								<TR>
								<TD style="TEXT-ALIGN: left"><SPAN
									id="yyyyyyyy" style="FONT-SIZE: small">考勤日期：</SPAN>
								<INPUT id="currentDate"
									style="FONT-SIZE: small; WIDTH: 86px; COLOR: #0000cc; HEIGHT: 16px"
									value="<%=new SimpleDateFormat("yyyy-MM-dd").format(dt.getWorkDate())%>"
									name="workdate" disabled="disabled"></TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label14 style="FONT-SIZE: small">工作时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox8
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=<%=dt.getWorkTime() %> name="workTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label15 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label16 style="FONT-SIZE: small">加班时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox9
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=<%=dt.getOverTime() %> name="overTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label17 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label18 style="FONT-SIZE: small">休假时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox10
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=<%=dt.getVocationTime() %> name="vocationTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label19 style="FONT-SIZE: small">小时</SPAN>
								</TD>
								<TD style="TEXT-ALIGN: right"><SPAN
									id=ctl00_ContentPlaceHolder1_Label20 style="FONT-SIZE: small">请假时间：</SPAN>
								<INPUT id=ctl00_ContentPlaceHolder1_TextBox11
									style="FONT-SIZE: small; WIDTH: 30px; COLOR: #0000cc; HEIGHT: 16px"
									value=<%=dt.getLeaveTime() %> name="leaveTime"> <SPAN
									id=ctl00_ContentPlaceHolder1_Label21 style="FONT-SIZE: small">小时</SPAN>
									
									<input type="hidden" name="workDate" value="<%=new SimpleDateFormat("yyyy-MM-dd").format(dt.getWorkDate())%>" />
									<input type="hidden" name="edit" value="edit"/>
									<input type="hidden" name="dailyTimingID" value="<%=dt.getDailyTimingID() %>" />
								</TD>
							</TR>
							<TR>
								<TD colSpan=5><TEXTAREA
									id=ctl00_ContentPlaceHolder1_TextBox12
									style="WIDTH: 99.5%; COLOR: #0000cc; HEIGHT: 80px"
									name="workSummary"><%=dt.getWorkSummary() %></TEXTAREA></TD>
							</TR>
								
						<%		
								}
						 %>
						
							<TR>
								<TD colSpan=5>
								
									<INPUT id=ctl00_ContentPlaceHolder1_Button2 type="submit" value="提 交" name="submit" onclick="return changeStatus('Pending')">
									&nbsp; 
									<INPUT id=ctl00_ContentPlaceHolder1_Button1 type="submit" value="暂 存" name="save" onclick="return changeStatus('Saved')"> 
									&nbsp; 
									<input type="hidden" name="status" value="" /> 
									
								</TD>
							</TR>
								
						</Form>
						</TBODY>
					</TABLE>
					</DIV>
					</TD>
				</TR>
			</TBODY>
		</TABLE>
	</TR>
</TABLE>
</DIV>

<jsp:include page="../footer.jsp"></jsp:include>
</BODY>
</HTML>
